//
// Created by qwq on 22-5-26.
//
#include "udp.hpp"

using namespace std;
int udp_init(const char* ip,uint16_t port)
{
    int fd = socket(AF_INET,SOCK_DGRAM,0);

    //连接服务器
    sockaddr_in saddr;
    saddr.sin_family = AF_INET;
    saddr.sin_port = htons(port);
    inet_pton(AF_INET,ip,&saddr.sin_addr.s_addr);
    int ret = connect(fd,(struct sockaddr*)&saddr,sizeof(saddr));
    if(ret == -1)
    {
        perror("connect failed!!!\n");
    }
    else
    {
        cout<<fd<<"connect successes!!!"<<endl;
    }
    return fd;
}